﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.IO;

namespace JSLCloud.App.Mes
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            var host = Host.CreateDefaultBuilder(args);
            var config = new ConfigurationBuilder()
                .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
                .AddJsonFile("appsettings.json")
                .Build();
#if (DEBUG)
            //DEBUG模式使用默认的启动路径
            host.ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder
               .UseConfiguration(config)               
               .ConfigureLogging((hostintContext, logging) =>
               {
                   logging.AddFilter("System", LogLevel.Warning);
                   logging.AddFilter("Microsoft", LogLevel.Warning);
                   logging.AddLog4Net("log4net.config");
               })
               .UseStartup<Startup>();
            });

#else
            //Release模式使用appsettings.json中的urls
             host.ConfigureWebHostDefaults(webBuilder =>
            {
                    webBuilder
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseKestrel()                
                    .UseIISIntegration()
                    .UseIIS()
                    .UseConfiguration(config)
                    .ConfigureLogging((hostintContext, logging) =>
                    {
                        logging.AddFilter("System", LogLevel.Warning);
                        logging.AddFilter("Microsoft", LogLevel.Warning);
                        logging.AddLog4Net();
                    })
                    .UseStartup<Startup>();
             });
#endif
            return host;
        }
    }
}
